import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import Loader from "./components/index.js";

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

// 用这个来网路请求
import api from "@/config/api";

import utils from "@/config/utils";
import "@/assets/css/pc.css";


import consts from "@/config/const";

// 绑定api
Vue.prototype.$api = api;

// 绑定工具
Vue.prototype.$utils = utils;

// 绑定常量
Vue.prototype.$const = consts;

Vue.use(ElementUI);

Vue.use(Loader);

Vue.config.productionTip = false

Vue.directive("outside-click", {
  bind: function(el, binding, vnode) {
    // 定义点击函数
    function clickHandler(e) {
      if (el.contains(e.target)) {
        // 如果点击区域在所在指令元素内部，则直接返回
        return false;
      }
      if (binding.expression) {
        // 如果定义了表达式，则执行表达式中的函数
        binding.value(e);
      }
    }

    el.vueOutsideClick = clickHandler;
    document.addEventListener("click", clickHandler); // 绑定到 document 的点击事件
  },
  unbind: function(el, binding, vnode) {
    document.removeEventListener("click", el.vueOutsideClick); // 解绑
    delete el.vueOutsideClick; // 销毁
  }
});


// 判断用户信息
let userId = utils.getUserId();
if(userId){
  // 说明记录的有登陆
  store.dispatch("getUserById",userId);
}



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
